home *** CD-ROM | disk | FTP | other *** search
- Path: news2.ios.com!usenet
- From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
- Newsgroups: comp.lang.c++
- Subject: Re: Is it possible to use templates with structures?
- Date: Fri, 02 Feb 1996 15:09:00 GMT
- Organization: Internet Online Services
- Message-ID: <4et8su$35t@news2.ios.com>
- References: <4eq9s5$l14@nntp.hut.fi>
- NNTP-Posting-Host: ppp-43.ts-7.hck.idt.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- casper@lk-hp-10.hut.fi (Casper Gripenberg) wrote:
-
-
-
- >Can I do:
-
- >template<class T>
- >struct Foo {
- > T *data;
- >};
-
- >??
-
- >The compiler doesn't seem to complain but I would still like to be
- >sure if it's ok to do it.
-
- >The reason I want to do it is that I need to allocate the structure
- >with my own allocation routine and not with new. Also I can't override
- >new in the class so that won't work either. While on the same subject
- >could I have a template class dontaining just data members and
- >no constructors/destructor or memberfunctions and then allocate
- >it without using new? As I understand it the only thing new does
- >that for example malloc doesn't do is run the constructor code. So
- >is it safe to use that kind of a template class allocated with malloc??
-
- >Thanks...
-
- I don't see any problem here since your code
-
- template<class T>
- struct Foo {
- T *data;
- };
-
- is understood by your compiler as a
-
- template<class T>
- class Foo
- {
- public:
- T *data;
- };
-
- and the latter is correct.
-
-
-
- *******************************************
- * Vlastimil Adamovsky *
- * Smalltalk, C++ and Envelop development *
- *******************************************
-
-